/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pa165.languageschoolpersistence.entities;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Jiri Uhlir
 *
 *  * Class representing entity Course. Course is an entity in language school,
 * that contains individual lectures.
 * @attribute ID course id, generated automatically, cannot be 0.
 * @attribute name name of the course. Must contain only small or large letters,
 * without punctation or special characters.
 * @attribute lectures list of lectures that course contains. List of students
 * enrolled in the course can be got from the list of lectures and their
 * students. Course can contain 0..* lectures.
 * @attribute language Language of the course from enum Language.
 * @attribute difficulty Difficulty of the course from enum Difficulty.
 */
@Entity
public class Course implements Serializable {

    /**
     * One course can contain multiple lectures
     */
    @OneToMany(mappedBy = "course", orphanRemoval = true, cascade = CascadeType.ALL)
    private List<Lecture> lectures = new ArrayList<Lecture>();
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    /**
     * Name of the course
     */
    @Column(name = "name", unique = true)
    private String name;
    /**
     * Difficulty of the course
     */
    private Difficulty difficulty;
    /**
     * Language of the course
     */
    private LanguageSpoken languageSpoken;

    public void addLecture(Lecture lecture) {
        if (lectures != null) {
            lectures.add(lecture);
        }
    }

    public List<Lecture> getLectures() {
        return lectures;
    }

    public void setLectures(List<Lecture> lectures) {
        this.lectures = lectures;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Difficulty getDifficulty() {
        return difficulty;
    }

    public void setDifficulty(Difficulty difficulty) {
        this.difficulty = difficulty;
    }

    public LanguageSpoken getLanguage() {
        return languageSpoken;
    }

    public void setLanguage(LanguageSpoken languageSpoken) {
        this.languageSpoken = languageSpoken;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Course)) {
            return false;
        }
        Course other = (Course) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Course[ id=" + id + ", name=" + name + " ,difficulty=" + this.difficulty + " ]";
    }
}
